<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="author" content="created by shirdon"/>
    <title>会员登录</title>
    <link rel="stylesheet" href="/static/frontend/css/login.css"/>
    <script src="/static/frontend/js/jquery-1.10.1.js"></script>
</head>
<body class="login_page">
<!-- login -->
<div class="top center">
    <div class="logo center">
        <a href="/" target="_blank"><img src="/static/frontend/image/logo_top.png" alt=""></a>
    </div>
</div>
<div class="login">
    <div class="login_center">
        <div class="login_top">
            <div class="left fl">会员登录</div>
            <div class="right fr">您还不是我们的会员？<a href="/auth/registerStep1" target="_self">立即注册</a></div>
            <div class="clear"></div>
            <div class="xian center"></div>
        </div>
        <div class="login_main center">
            <input type="hidden" id="prevPage" value="{{.prevPage}}">
            <div class="username">手机号：<input class="inputclass" id="phone" type="text" name="phone"
                                             placeholder="请输入你的用户名"/></div>
            <div class="username">密　码：<input class="inputclass" id="password" type="password" name="password"
                                             placeholder="请输入你的密码"/></div>
            <div class="username">
                <div class="left fl">验证码：<input class="verificode" id="phone_code" type="text" name="phone_code"
                                                placeholder="请输入验证码"/></div>
                <div class="right fl">
                {{create_captcha}}
                </div>
                <div class="clear"></div>
            </div>
        </div>
        <div class="error">
        </div>
        <div class="login_submit">
            <input class="submit" type="button" id="goLogin" value="立即登录">
        </div>
    </div>
</div>
<footer>
    <div class="copyright">简体 | 繁体 | English | 常见问题</div>
    <div class="copyright">LeastMall版权所有-蜀ICP备xxxxxxx-<img src="/public/default/image/ghs.png" alt="">京公网安备xxxxxxxxxxxxx号-京ICP证xxxxxx号
    </div>
</footer>
<script>
    $(function () {
        $("#goLogin").click(function (e) {
            var phone = $('#phone').val();
            var password = $('#password').val();
            var phone_code = $('#phone_code').val();
            var phoneCodeId = $("input[name='captcha_id']").val();
            var prevPage = $("#prevPage").val();
            var reg = /^[\d]{11}$/;
            if (!reg.test(phone)) {
                alert('手机号输入错误');
                return false;
            }
            if (password.length < 6) {
                alert('密码长度不合法');
                return false;
            }
            if (phone_code.length < 4) {
                alert('验证码长度不合法');
                return false;
            }
            //ajax请求
            $.post('/auth/goLogin', {
                phone: phone,
                password: password,
                phone_code: phone_code,
                phoneCodeId: phoneCodeId
            }, function (response) {
                console.log(response);
                if (response.success == true) {
                    if (prevPage) {
                        location.href = prevPage;
                    } else {
                        location.href = "/";
                    }
                } else {
                    //改变验证码
                    $(".error").html("Error：" + response.msg + ",请重新输入!")
                    //改变验证码
                    var captchaImgSrc = $(".captcha-img").attr("src")
                    $(".phone_code").val("")
                    $(".captcha-img").attr("src", captchaImgSrc +
                            "?reload=" + (new Date()).getTime())
                }
            })
        })
    })
</script>
</body>
</html>